package huawei;

import java.util.*;

public class Main {
    static int sum(int num) {
        int result = 0;
        while (num > 0) {
            result += num % 10;
            num = num / 10;
        }

        return result < 10 ? result : sum(result);
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int num = in.nextInt();

        int result = 0;

        if (num <= 9) {
            System.out.println(num);
        }
        result = sum(num);
        System.out.println(result);
        in.close();
    }
}